package com.hjm.project.weaningGear.weaningGear.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.weaningGear.weaningGear.domain.WeaningGear;
import com.hjm.project.weaningGear.weaningGear.service.IWeaningGearService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 撤机归档记录Controller
 * 
 * @author maker-platform
 * @date 2021-01-26
 */
@Controller
@RequestMapping("/weaningGear/weaningGear")
public class WeaningGearController extends BaseController
{
    private String prefix = "weaningGear/weaningGear";

    @Autowired
    private IWeaningGearService weaningGearService;

    @RequiresPermissions("weaningGear:weaningGear:view")
    @GetMapping()
    public String weaningGear()
    {
        return prefix + "/weaningGear";
    }

    /**
     * 查询撤机归档记录列表
     */
    @RequiresPermissions("weaningGear:weaningGear:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WeaningGear weaningGear)
    {
        startPage();
        List<WeaningGear> list = weaningGearService.selectWeaningGearList(weaningGear);
        return getDataTable(list);
    }

    /**
     * 导出撤机归档记录列表
     */
    @RequiresPermissions("weaningGear:weaningGear:export")
    @Log(title = "撤机归档记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WeaningGear weaningGear)
    {
        List<WeaningGear> list = weaningGearService.selectWeaningGearList(weaningGear);
        ExcelUtil<WeaningGear> util = new ExcelUtil<WeaningGear>(WeaningGear.class);
        return util.exportExcel(list, "weaningGear");
    }

    /**
     * 新增撤机归档记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存撤机归档记录
     */
    @RequiresPermissions("weaningGear:weaningGear:add")
    @Log(title = "撤机归档记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WeaningGear weaningGear)
    {
        return toAjax(weaningGearService.insertWeaningGear(weaningGear));
    }

    /**
     * 修改撤机归档记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WeaningGear weaningGear = weaningGearService.selectWeaningGearById(id);
        mmap.put("weaningGear", weaningGear);
        return prefix + "/edit";
    }

    /**
     * 修改保存撤机归档记录
     */
    @RequiresPermissions("weaningGear:weaningGear:edit")
    @Log(title = "撤机归档记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WeaningGear weaningGear)
    {
        return toAjax(weaningGearService.updateWeaningGear(weaningGear));
    }

    /**
     * 删除撤机归档记录
     */
    @RequiresPermissions("weaningGear:weaningGear:remove")
    @Log(title = "撤机归档记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(weaningGearService.deleteWeaningGearByIds(ids));
    }
}
